package com.yanqu.road.server.cmd.activity.luckydraw;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LuckyDrawProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.RealRewardModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_LUCKY_DRAW_SET_ADDR, desc = "")
public class LuckyDrawSetAddrCmd extends AbstractCommand {

    private LuckyDrawProto.LuckyDrawSetAddrReqMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = LuckyDrawProto.LuckyDrawSetAddrReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        int no = reqMsg.hasNo() ? reqMsg.getNo() : -1;
        ret = player.getModule(RealRewardModule.class).setAddr(reqMsg.getGoodsId(), reqMsg.getPhone(), reqMsg.getAddr(), no);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            LuckyDrawProto.LuckyDrawSetAddrRespMsg.Builder builder = LuckyDrawProto.LuckyDrawSetAddrRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_LUCKY_DRAW_SET_ADDR, builder);
        }
    }

}
